/**
 * Copyright 2009 University of  Washington
 * This code is released under the GPL version 3 - with a copy of the license included
 * @author Maya Hao Li
 *
 */package seedpod.model;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

import seedpod.model.SeedpodModel.RdbCls.FormWidget;
import seedpod.model.SeedpodModel.RdbCls.USER_GROUP;
import seedpod.model.SeedpodModel.RdbCls.ViewWidget;
import seedpod.model.rdb.RdbValueType;
import edu.stanford.smi.protege.model.Cls;
import edu.stanford.smi.protege.model.Frame;
import edu.stanford.smi.protege.model.FrameID;
import edu.stanford.smi.protege.model.KnowledgeBase;
import edu.stanford.smi.protege.model.Model;
import edu.stanford.smi.protege.model.RoleConstraint;
import edu.stanford.smi.protege.model.Slot;
import edu.stanford.smi.protege.model.SystemFrames;
import edu.stanford.smi.protege.model.ValueType;

public class SeedpodSystemFrames extends SystemFrames
{
	private KnowledgeBase _kb;
	private Map<FrameID, String> _frameIdToNameMap = new LinkedHashMap<FrameID, String>();
	private Map<FrameID, Frame> _frameIdToFrameMap = new LinkedHashMap<FrameID, Frame>();
	private Collection<String> _initErrors = new ArrayList<String>();

	public SeedpodSystemFrames(KnowledgeBase kb) {
		super( kb );
		_kb = kb;
	}

	/**
	 * create classes and slots specific to seedpod
	 *
	 */
	public void createSeedpodSystemFrames() {
		createSeedpodClses();
		createSeedpodSlot();
		configureClses();
		configureSlots();
	}

	public void setDefaultClsMetaCls() {
		_kb.setDefaultClsMetaCls( getSeedpodClsMetaCls() );
	}

	public void setDefaultSlotMetaCls() {
		_kb.setDefaultSlotMetaCls( getSeedpodSlotMetaCls() );
	}

	protected void createSeedpodClses() {
		// metaclasses
		addCls( SeedpodModel.RdbCls.RDB_CLASS, Model.Cls.STANDARD_CLASS, Model.Cls.STANDARD_CLASS );
		addCls( SeedpodModel.RdbCls.RDB_SLOT, Model.Cls.STANDARD_SLOT, Model.Cls.STANDARD_CLASS );
		addCls( SeedpodModel.RdbCls.DATABASE, Model.Cls.STANDARD_CLASS, Model.Cls.STANDARD_CLASS );
		addCls( SeedpodModel.RdbCls.SEEDPOD_MODEL, Model.Cls.STANDARD_CLASS, Model.Cls.STANDARD_CLASS );

		addCls( SeedpodModel.RdbCls.REIFIED_SLOT_CLS, Model.Cls.SYSTEM_CLASS, SeedpodModel.RdbCls.RDB_CLASS );
		addCls( SeedpodModel.RdbCls.USER, Model.Cls.SYSTEM_CLASS, SeedpodModel.RdbCls.RDB_CLASS );
		addCls( SeedpodModel.RdbCls.ACCESS_LOG, Model.Cls.SYSTEM_CLASS, SeedpodModel.RdbCls.RDB_CLASS );
		addCls( SeedpodModel.RdbCls.ANNOTATION, Model.Cls.SYSTEM_CLASS, SeedpodModel.RdbCls.RDB_CLASS );
		addCls( SeedpodModel.RdbCls.DATA_TYPE, Model.Cls.SYSTEM_CLASS, Model.Cls.STANDARD_CLASS );
		addCls( SeedpodModel.RdbCls.TYPE_DATE, SeedpodModel.RdbCls.DATA_TYPE, SeedpodModel.RdbCls.RDB_CLASS );
		addCls( SeedpodModel.RdbCls.TYPE_TIME, SeedpodModel.RdbCls.DATA_TYPE, SeedpodModel.RdbCls.RDB_CLASS );
		addCls( SeedpodModel.RdbCls.TYPE_3D_COORDINANTS, SeedpodModel.RdbCls.DATA_TYPE, SeedpodModel.RdbCls.RDB_CLASS );
		addCls( SeedpodModel.RdbCls.TYPE_FILE, SeedpodModel.RdbCls.DATA_TYPE, SeedpodModel.RdbCls.RDB_CLASS );
	}

	protected Frame addCls( String clsName, String parentCls, String metaCls ) {
		Frame frame = _kb.getFrame( clsName );
		if ( frame == null ) {
			frame = createCls( clsName, _kb.getCls( parentCls ), _kb.getCls( metaCls ) );
		}

		FrameID id = frame.getFrameID();
		_frameIdToNameMap.put( id, clsName );
		_frameIdToFrameMap.put( id, frame );
		return frame;
	}

	// cls specific
	protected Cls createCls( String name, Cls parent, Cls metaCls ) {
		ArrayList<Cls> parents = new ArrayList<Cls>();
		parents.add( parent );

		ArrayList<Cls> metaClses = new ArrayList<Cls>();
		metaClses.add( metaCls );

		return _kb.createCls( name, parents, metaCls );
	}

	protected void createSeedpodSlot() {
		// slots for rdb_class
		addSlot( SeedpodModel.RdbSlot.USER_ASSIGNED_NAME, SeedpodModel.RdbCls.RDB_CLASS );
		addSlot( SeedpodModel.RdbSlot.DATA_SOURCE, SeedpodModel.RdbCls.RDB_CLASS );
		addSlot( SeedpodModel.RdbSlot.INLINE, SeedpodModel.RdbCls.RDB_CLASS );
		addSlot( SeedpodModel.RdbSlot.JAVA_CLASS, SeedpodModel.RdbCls.RDB_CLASS);
		// slots for rdb_attributes
		addSlot( SeedpodModel.RdbSlot.USER_ASSIGNED_NAME, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.DATABASE_INDEX, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.DATABASE_TYPE, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.DATABASE_TYPE_PARAMETER, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.FORM_WIDGET, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.FORM_WIDGET_PARAMETER, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.PERMISSION, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.UNIQUE, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.UNIT, SeedpodModel.RdbCls.RDB_SLOT );
		// SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.VALUE_EXPRESSION, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.VIEW_SEQUENCE, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.VIEW_WIDGET, SeedpodModel.RdbCls.RDB_SLOT );
		addSlot( SeedpodModel.RdbSlot.VIEW_WIDGET_PARAMETER, SeedpodModel.RdbCls.RDB_SLOT );
		// slots for seedpod_model
		addSlot( SeedpodModel.RdbSlot.MODEL_CREATOR, SeedpodModel.RdbCls.SEEDPOD_MODEL );
		addSlot( SeedpodModel.RdbSlot.MODEL_DATE, SeedpodModel.RdbCls.SEEDPOD_MODEL );
		addSlot( SeedpodModel.RdbSlot.MODEL_VERSION, SeedpodModel.RdbCls.SEEDPOD_MODEL );
		// slots for database
		addSlot( SeedpodModel.RdbSlot.DATABASE_JDBC, SeedpodModel.RdbCls.DATABASE );
		addSlot( SeedpodModel.RdbSlot.DATABASE_NAME, SeedpodModel.RdbCls.DATABASE );
		addSlot( SeedpodModel.RdbSlot.DATABASE_PASSWORD, SeedpodModel.RdbCls.DATABASE );
		addSlot( SeedpodModel.RdbSlot.DATABASE_URL, SeedpodModel.RdbCls.DATABASE );
		addSlot( SeedpodModel.RdbSlot.DATABASE_USERNAME, SeedpodModel.RdbCls.DATABASE );
		// slots for user
		addSlot( SeedpodModel.RdbSlot.FIRST_NAME, SeedpodModel.RdbCls.USER );
		addSlot( SeedpodModel.RdbSlot.LAST_NAME, SeedpodModel.RdbCls.USER );
		addSlot( SeedpodModel.RdbSlot.USERNAME, SeedpodModel.RdbCls.USER );
		addSlot( SeedpodModel.RdbSlot.USER_GROUP, SeedpodModel.RdbCls.USER );
		addSlot( SeedpodModel.RdbSlot.PASSWORD, SeedpodModel.RdbCls.USER );
		addSlot( SeedpodModel.RdbSlot.EMAIL, SeedpodModel.RdbCls.USER );
		// slots for access_log
		addSlot( SeedpodModel.RdbSlot.ACCESS_USER, SeedpodModel.RdbCls.ACCESS_LOG );
		addSlot( SeedpodModel.RdbSlot.ACCESS_ACTION, SeedpodModel.RdbCls.ACCESS_LOG );
		addSlot( SeedpodModel.RdbSlot.ACCESS_TIMESTAMP, SeedpodModel.RdbCls.ACCESS_LOG );
		// slots for Annotation
		addSlot( SeedpodModel.RdbSlot.ANNOTATION_OBJECT, SeedpodModel.RdbCls.ANNOTATION );
		addSlot( SeedpodModel.RdbSlot.ANNOTATION_ATTRIBUTE, SeedpodModel.RdbCls.ANNOTATION );
		addSlot( SeedpodModel.RdbSlot.ANNOTATION_USER, SeedpodModel.RdbCls.ANNOTATION );
		addSlot( SeedpodModel.RdbSlot.ANNOTATION_TIMESTAMP, SeedpodModel.RdbCls.ANNOTATION );
		addSlot( SeedpodModel.RdbSlot.ANNOTATION_TAG, SeedpodModel.RdbCls.ANNOTATION );
		addSlot( SeedpodModel.RdbSlot.ANNOTATION_COMMENT, SeedpodModel.RdbCls.ANNOTATION );
		
		// slots for Date
		addSlot( SeedpodModel.RdbSlot.YEAR, SeedpodModel.RdbCls.TYPE_DATE );
		addSlot( SeedpodModel.RdbSlot.MONTH, SeedpodModel.RdbCls.TYPE_DATE );
		addSlot( SeedpodModel.RdbSlot.DAY, SeedpodModel.RdbCls.TYPE_DATE );
		// slots for time
		addSlot( SeedpodModel.RdbSlot.HOUR, SeedpodModel.RdbCls.TYPE_TIME );
		addSlot( SeedpodModel.RdbSlot.MINUTE, SeedpodModel.RdbCls.TYPE_TIME );
		addSlot( SeedpodModel.RdbSlot.SECOND, SeedpodModel.RdbCls.TYPE_TIME );
		// slots for 3d coordinates
		addSlot( SeedpodModel.RdbSlot.COORDINATE_UNIT, SeedpodModel.RdbCls.TYPE_3D_COORDINANTS );
		addSlot( SeedpodModel.RdbSlot.X, SeedpodModel.RdbCls.TYPE_3D_COORDINANTS );
		addSlot( SeedpodModel.RdbSlot.Y, SeedpodModel.RdbCls.TYPE_3D_COORDINANTS );
		addSlot( SeedpodModel.RdbSlot.Z, SeedpodModel.RdbCls.TYPE_3D_COORDINANTS );
		// slots for file
		addSlot( SeedpodModel.RdbSlot.SUBMIT_DATE, SeedpodModel.RdbCls.TYPE_FILE );
		addSlot( SeedpodModel.RdbSlot.MIME_TYPE, SeedpodModel.RdbCls.TYPE_FILE );
		addSlot( SeedpodModel.RdbSlot.VERSION, SeedpodModel.RdbCls.TYPE_FILE );
		addSlot( SeedpodModel.RdbSlot.DESCRIPTION, SeedpodModel.RdbCls.TYPE_FILE );
		addSlot( SeedpodModel.RdbSlot.DOMAIN, SeedpodModel.RdbCls.TYPE_FILE );
		addSlot( SeedpodModel.RdbSlot.LABEL, SeedpodModel.RdbCls.TYPE_FILE );
		addSlot( SeedpodModel.RdbSlot.SOURCE, SeedpodModel.RdbCls.TYPE_FILE );
	}

	protected void addSlot( String slotName, String domainClsName ) {
		Frame sFrame = _kb.getFrame( slotName );
		Cls domainCls = _kb.getCls( domainClsName );
		Slot slot;

		if ( domainCls == null )
			return;
		if ( sFrame == null )
			slot = createSlot( slotName, _kb.getCls( SeedpodModel.RdbCls.RDB_SLOT ) );
		else
			slot = (Slot)sFrame;

		if ( !_kb.hasTemplateSlot( domainCls, slot ) )
			_kb.addDirectTemplateSlot( domainCls, slot );
	}

	protected Slot createSlot( String slotName, Cls metaCls ) {
		return _kb.createSlot( slotName, metaCls );
	}

	public Cls getSeedpodClsMetaCls() {
		return _kb.getCls( SeedpodModel.RdbCls.RDB_CLASS );
	}

	public Cls getSeedpodSlotMetaCls() {
		return _kb.getCls( SeedpodModel.RdbCls.RDB_SLOT );
	}

	public Collection<String> getErrors() {
		return _initErrors;
	}

	protected void configureClses() {
		configureCls( getDataTypeCls(), RoleConstraint.ABSTRACT );
		configureCls( getReifiedSlotClsCls(), RoleConstraint.ABSTRACT );

	}

	protected void configureClsInline( String clsName, boolean inline ) {
		Cls cls = _kb.getCls( clsName );
		Slot inlineSlot = getIsInlineSlot();
		cls.setDirectOwnSlotValue( inlineSlot, new Boolean( inline ) );
	}

	protected void configureSlots() {

		// configure rdbcls slots
		configureInstanceSlot( getDataSourceSlot(), getDatabaseCls(), 0, 1 );
		configureBooleanValueSlot( getIsInlineSlot(), false );
		configureStringSlot( getUserDefinedNameSlot(), 0, 1 );
		configureStringSlot( getJavaClassSlot(), 0, 1);

		configureClsInline( SeedpodModel.RdbCls.TYPE_DATE, true );
		configureClsInline( SeedpodModel.RdbCls.TYPE_TIME, true );
		configureClsInline( SeedpodModel.RdbCls.TYPE_3D_COORDINANTS, true );

		// configure seedpod model slots
		configureInstanceSlot( getModelCreatorSlot(), getUserCls(), 1, 1 );
		configureInstanceSlot( getModelDateSlot(), getDateCls(), 1, 1 );
		configureStringSlot( getModelVersionSlot(), 1, 1 );

		// configure database slots
		configureStringSlot( getDatabaseJDBCSlot(), 1, 1 );
		configureStringSlot( getDatabaseNameSlot(), 1, 1 );
		configureStringSlot( getDatabasePasswordSlot(), 1, 1 );
		configureStringSlot( getDatabaseUserNameSlot(), 1, 1 );
		configureStringSlot( getDatabaseURLSlot(), 1, 1 );

		// configure rdb attribute slots
		configureSymbolValueSlot( getPermissionSlot(),   SeedpodModel.RdbCls.PERMISSION.values() );
		configureSymbolValueSlot( getDatabaseTypeSlot(), RdbValueType.values() );
		configureSymbolValueSlot( getFormWidgetSlot(),  FormWidget.values() );
		configureSymbolValueSlot( getViewWidgetSlot(), ViewWidget.values());

		configureStringSlot( getDatabaseTypeParameterSlot(), 0, 1 );
		configureStringSlot( getFormWidgetParameterSlot(), 0, 1 );
		configureStringSlot( getViewWidgetParameterSlot(), 0, 1 );
		configureStringSlot( getValueExpressionSlot(), 0, 1 );

		configureStringSlot( getUnitSlot(), 0, 1 );
		configureBooleanValueSlot( getIsUniqueSlot(), false );
		configureBooleanValueSlot( getIsDatabaseIndexSlot(), false );

		configureFloatValueSlot( getViewSequenceSlot(), 0, 1 );

		// configure date slot
		configureIntegerValueSlot( getDaySlot(), 1, 31 );
		configureIntegerValueSlot( getMonthSlot(), 1, 12 );
		configureIntegerValueSlot( getYearSlot() );

		// configure time slots
		configureIntegerValueSlot( getHourSlot(), 0, 23 );
		configureIntegerValueSlot( getMinuteSlot(), 0, 59 );
		configureIntegerValueSlot( getSecondSlot(), 0, 59 );

		// configure user slots
		configureStringSlot( getPasswordSlot(), 1, 1 );
		configureStringSlot( getLastNameSlot(), 0, 1 );
		configureStringSlot( getFirstNameSlot(), 0, 1 );
		configureStringSlot( getUserNameSlot(), 1, 1 );
		configureStringSlot( getEmailSlot(), 0, 1 );
		configureSymbolValueSlot( getUserGroupSlot(), USER_GROUP.values() );
		
		configureDatabaseTypeParameter( getPasswordSlot(), String.valueOf(50) );
		configureDatabaseTypeParameter( getFirstNameSlot(), String.valueOf(50) );
		configureDatabaseTypeParameter( getUserNameSlot(), String.valueOf(20) );
		configureDatabaseTypeParameter( getEmailSlot(), String.valueOf(100) );
		configureDatabaseTypeParameter( getLastNameSlot(), String.valueOf(50) );		

		// configure file slots
		configureStringSlot( getSubmitDateSlot(), 0, 1 );
		configureStringSlot( getMimeTypeSlot(), 0, 1 );
		configureStringSlot( getVersionSlot(), 0, 1 );
		configureStringSlot( getDescriptionSlot(), 0, 1 );
		configureStringSlot( getDomainSlot(), 0, 1 );
		configureStringSlot( getLabelSlot(), 0, 1 );
		configureStringSlot( getSourceSlot(), 0, 1 );

		// configure access_log slots
		configureInstanceSlot( getAccessUserSlot(), getUserCls(), 1, 1 );
		configureStringSlot( getAccessActionSlot(), 1, 1 );
		configureDatabaseTypeParameter( getAccessActionSlot(), String.valueOf( 255) );
		configureStringSlot( getAccessTimestampSlot(), 1, 1 );
		configureDatabaseTypeSlot(getAccessTimestampSlot(),  RdbValueType .TIMESTAMP.toString());
		configureDefaultValueSlot( getAccessTimestampSlot(), "CURRENT_TIMESTAMP");
		
		// configure annotation slots
		configureInstanceSlot( getAnnotationObjectSlot(), getThingCls(), 0, 1);
		configureStringSlot( getAnnotationAttributeSlot(), 0, 1);
		configureStringSlot( getAnnotationTagSlot(), 1, 1);
		configureStringSlot( getAnnotationCommentSlot(), 1, 1);
		configureInstanceSlot( getAnnotationUserSlot(), getUserCls(), 1, 1);
		configureStringSlot( getAnnotationTimestampSlot(), 1, 1);
	}

	private void configureSymbolValueSlot( Slot slot, Object[] values ) {
		String[] strVal = new String[values.length]; 
		for ( int i = 0; i < values.length; i++ )
			strVal[i] = values[i].toString();
		configureSymbolValueSlot( slot, strVal ); 
	}

	private Slot getJavaClassSlot() {
		return _kb.getSlot(SeedpodModel.RdbSlot.JAVA_CLASS);
	}

	private Slot getUserDefinedNameSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.USER_ASSIGNED_NAME );
	}

	private Slot getAnnotationTimestampSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.ANNOTATION_TIMESTAMP );
	}

	private Slot getAnnotationUserSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.ANNOTATION_USER );
	}

	private Slot getAnnotationCommentSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.ANNOTATION_COMMENT );
	}

	private Slot getAnnotationTagSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.ANNOTATION_TAG );
	}

	private Slot getAnnotationAttributeSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.ANNOTATION_ATTRIBUTE );
	}
	
	

	private Cls getThingCls() {
		return _kb.getCls( Model.Cls.THING );
	}

	private Slot getAnnotationObjectSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.ANNOTATION_OBJECT );
	}
	
	

	private void configureDefaultValueSlot( Slot slot, Object dval ) {
		Collection<Object> defaultVal = new ArrayList<Object>();
		defaultVal.add(dval);
		slot.setDefaultValues( defaultVal );
	}

	private void configureDatabaseTypeSlot( Slot slot, String dbtype ) {
		Slot dbTypeSlot = getDatabaseTypeSlot();
		slot.setOwnSlotValue( dbTypeSlot, dbtype );
	}

	private void configureDatabaseTypeParameter( Slot slot, String lengthVal ) {
		Slot dataParamSlot = getDatabaseTypeParameterSlot();
		slot.setOwnSlotValue( dataParamSlot, lengthVal );
	}

	@SuppressWarnings("unused")
	private void configureValueExpression( Slot slot, String stringVal ) {
		Slot expressionSlot = getValueExpressionSlot();
		slot.setOwnSlotValue( expressionSlot, stringVal );
	}

	private void configureIntegerValueSlot( Slot slot, int min, int max ) {
		_kb.setValueType( slot, ValueType.INTEGER );
		_kb.setMinimumValue( slot, min );
		_kb.setMaximumValue( slot, max );
	}

	private void configureFloatValueSlot( Slot slot, int minCar, int maxCar ) {
		_kb.setValueType( slot, ValueType.FLOAT );
		_kb.setMinimumCardinality( slot, minCar );
		_kb.setMaximumCardinality( slot, maxCar );
	}

	private void configureBooleanValueSlot( Slot slot, boolean defaultBoolean ) {
		_kb.setValueType( slot, ValueType.BOOLEAN );
		configureDefaultValueSlot( slot, Boolean.valueOf( defaultBoolean ) );
	}

	private void configureCls( Cls cls, String role ) {
		_kb.setAbstract( cls, role.compareTo( RoleConstraint.ABSTRACT ) == 0 );
	}

	private void configureInstanceSlot( Slot slot, Cls cls, int min, int max ) {
		_kb.setMinimumCardinality( slot, min );
		_kb.setMaximumCardinality( slot, max );
		_kb.setAllowsMultipleValues( slot, (max > 1) );
		_kb.setValueType( slot, ValueType.INSTANCE );

		if ( cls != null ) {
			Collection<Cls> allowedClses = new ArrayList<Cls>();
			allowedClses.add( cls );
			_kb.setAllowedClses( slot, allowedClses );
		}
	}

	/*
	 * private void configureInstanceSlot( String slotName, Cls cls, int min,
	 * int max ) { Slot slot = _kb.getSlot( slotName ); configureInstanceSlot(
	 * slot, cls, min, max ); }
	 */

	private void configureStringSlot( Slot slot, int min, int max ) {
		_kb.setValueType( slot, ValueType.STRING );
		slot.setMinimumCardinality( min );
		slot.setMaximumCardinality( max );
	}

	private void configureSymbolValueSlot( Slot slot, String[] allowedValues ) {
		Collection<String> values = new ArrayList<String>();
		for ( int i = 0; i < allowedValues.length; i++ ) {
			values.add( allowedValues[i] );
		}
		_kb.setValueType( slot, ValueType.SYMBOL );
		_kb.setAllowedValues( slot, values );

		Collection<String> defaultVal = new ArrayList<String>();
		defaultVal.add( allowedValues[0] );
		_kb.setDefaultValues( slot, defaultVal );
	}

	// class getters
	public Cls getDefaultClsMetaCls() {
		return _kb.getDefaultClsMetaCls();
	}

	public Cls getDefaultSlotMetaCls() {
		return _kb.getDefaultSlotMetaCls();
	}

	public Cls getDataTypeCls() {
		return _kb.getCls( SeedpodModel.RdbCls.DATA_TYPE );
	}

	public Cls getReifiedSlotClsCls() {
		return _kb.getCls( SeedpodModel.RdbCls.REIFIED_SLOT_CLS );
	}

	public Cls getDatabaseCls() {
		return _kb.getCls( SeedpodModel.RdbCls.DATABASE );
	}

	public Cls getUserCls() {
		return _kb.getCls( SeedpodModel.RdbCls.USER );
	}

	public Cls getDateCls() {
		return _kb.getCls( SeedpodModel.RdbCls.TYPE_DATE );
	}

	public Cls getUnitCls() {
		return _kb.getCls( SeedpodModel.RdbCls.UNIT );
	}

	// slot getters
	public Slot getDataSourceSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATA_SOURCE );
	}

	public Slot getUserAssignedNameSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.USER_ASSIGNED_NAME );
	}

	public Slot getIsUniqueSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.UNIQUE );
	}

	public Slot getDatabaseTypeSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATABASE_TYPE );
	}

	public Slot getDatabaseTypeParameterSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATABASE_TYPE_PARAMETER );
	}

	public Slot getIsDatabaseIndexSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATABASE_INDEX );
	}

	public Slot getFormWidgetSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.FORM_WIDGET );
	}

	public Slot getFormWidgetParameterSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.FORM_WIDGET_PARAMETER );
	}

	public Slot getIsInlineSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.INLINE );
	}
	
	public Slot getDatabaseIndexSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATABASE_INDEX );
	}

	public Slot getPermissionSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.PERMISSION );
	}

	public Slot getUnitSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.UNIT );
	}

	public Slot getValueExpressionSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.VALUE_EXPRESSION );
	}

	public Slot getViewSequenceSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.VIEW_SEQUENCE );
	}

	public Slot getViewWidgetSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.VIEW_WIDGET );
	}

	public Slot getViewWidgetParameterSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.VIEW_WIDGET_PARAMETER );
	}

	public Slot getModelCreatorSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.MODEL_CREATOR );
	}

	public Slot getModelDateSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.MODEL_DATE );
	}

	public Slot getModelVersionSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.MODEL_VERSION );
	}

	public Slot getDatabaseJDBCSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATABASE_JDBC );
	}

	public Slot getDatabaseNameSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATABASE_NAME );
	}

	public Slot getDatabasePasswordSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATABASE_PASSWORD );
	}

	public Slot getDatabaseUserNameSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATABASE_USERNAME );
	}

	public Slot getDatabaseURLSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DATABASE_URL );
	}

	public Slot getDaySlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DAY );
	}

	public Slot getMonthSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.MONTH );
	}

	public Slot getYearSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.YEAR );
	}

	public Slot getSecondSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.SECOND );
	}

	public Slot getMinuteSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.MINUTE );
	}

	public Slot getHourSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.HOUR );
	}


	public Slot getUserGroupSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.USER_GROUP );
	}

	public Slot getEmailSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.EMAIL );
	}

	public Slot getUserNameSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.USERNAME );
	}

	public Slot getFirstNameSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.FIRST_NAME );
	}

	public Slot getLastNameSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.LAST_NAME );
	}

	public Slot getPasswordSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.PASSWORD );
	}

	public void configureIntegerValueSlot( Slot slot ) {
		_kb.setValueType( slot, ValueType.INTEGER );

	}

	public Slot getSourceSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.SOURCE );
	}

	public Slot getLabelSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.LABEL );
	}

	public Slot getDomainSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DOMAIN );
	}

	public Slot getDescriptionSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.DESCRIPTION );
	}

	public Slot getVersionSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.VERSION );
	}

	public Slot getMimeTypeSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.MIME_TYPE );
	}

	public Slot getSubmitDateSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.SUBMIT_DATE );
	}

	public boolean isSeedpodSystemMetaCls( Cls clsMetaCls ) {
		if ( clsMetaCls.equals( getSeedpodClsMetaCls() ) || clsMetaCls.hasSuperclass( getSeedpodClsMetaCls() )
				|| clsMetaCls.equals( getDatabaseCls() ) || clsMetaCls.hasSuperclass( getDatabaseCls() )
				|| clsMetaCls.equals( getSeedpodModelCls() ) || clsMetaCls.hasSuperclass( getSeedpodModelCls() ) )
			return true;
		else
			return false;
	}

	public Cls getSeedpodModelCls() {
		return _kb.getCls( SeedpodModel.RdbCls.SEEDPOD_MODEL );
	}

	public Cls getAccessLogCls() {
		return _kb.getCls( SeedpodModel.RdbCls.ACCESS_LOG );
	}

	private Slot getAccessUserSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.ACCESS_USER );
	}

	private Slot getAccessActionSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.ACCESS_ACTION );
	}

	private Slot getAccessTimestampSlot() {
		return _kb.getSlot( SeedpodModel.RdbSlot.ACCESS_TIMESTAMP );
	}


}
